package com.guaju.yueshangLife.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.activity.mine.OrderDetailActivity;
import com.guaju.yueshangLife.adapter.CommentGoodsAdapter;
import com.guaju.yueshangLife.adapter.DeliveryAdapter;
import com.guaju.yueshangLife.adapter.OrderDetailInnerAdapter;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.bean.MeOrder;
import com.guaju.yueshangLife.bean.MineOrder;
import com.guaju.yueshangLife.bean.OrderDetailBean;
import com.guaju.yueshangLife.databinding.ActivityCommentGoodsListBinding;
import com.guaju.yueshangLife.databinding.ActivityDiliveryDetailBinding;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class CommentGoodsListActivity extends BaseActivity {


    private ActivityCommentGoodsListBinding binding;
    private int orderId;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_comment_goods_list);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

        Intent intent = getIntent();
        if (intent.hasExtra("orderId")) {
//            List<MineOrder.DataBean.ItemsBean> goodsList =  intent.getParcelableArrayListExtra("goodsList");
            orderId = intent.getIntExtra("orderId", 0);
            ApiEntity.orderDetail(orderId);


        }
    }

    @Override
    protected void setListener() {

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void showEmpty() {
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onOrderDetailReceived(OrderDetailBean bean) {
        if (bean == null) {
            showEmpty();
        } else {
            OrderDetailBean.DataBean data = bean.getData();
            List<OrderDetailBean.DataBean.ItemsBean> items = data.getItems();
            ArrayList<OrderDetailBean.DataBean.ItemsBean> itemsBeans = new ArrayList<>();
            for (OrderDetailBean.DataBean.ItemsBean itemsBean : items) {
                int is_review = itemsBean.getIs_review();
                if (0 == is_review) {
                    itemsBeans.add(itemsBean);
                }
            }

            CommentGoodsAdapter commentGoodsAdapter = new CommentGoodsAdapter(CommentGoodsListActivity.this, itemsBeans);
            commentGoodsAdapter.setOrderId(orderId);
            binding.recyclerView.setAdapter(commentGoodsAdapter);
        }
    }

}
